def smallest_subarray_with_given_sum(s, arr):
  _sum = 0
  start = 0
  min_length = len(arr)+10
  print("input"+str(arr))
  for end in range(len(arr)):
    _sum += arr[end]
    while(_sum>=s):
      min_length = min(min_length,end-start+1)
      _sum -= arr[start]
      start += 1

  return min_length


def main():
  print("Smallest subarray length: " + str(smallest_subarray_with_given_sum(7, [2, 1, 5, 2, 3, 2])))
  print("Smallest subarray length: " + str(smallest_subarray_with_given_sum(7, [2, 1, 5, 2, 8])))
  print("Smallest subarray length: " + str(smallest_subarray_with_given_sum(8, [3, 4, 1, 1, 6])))


main()